<?php
    class category_edit_controller extends controllerBase
    {
        public function process()
        {
            if(isset($_POST['val']))
            {
                if(empty($_POST['val']['title']))
                {
                    return $this->url->getLink('admin/category/add',true, 'Title can not be null.');
                }
                if($this->database->update('category',$_POST['val'],'category_id = '.$this->iId))
                {
                    return $this->url->getLink('admin/category/', true, 'Update category successful.');
                }
            }
            $ocategory = $this->database->getObject('SELECT * FROM category WHERE category_id ='.$this->iId);
            if(!$ocategory)
            {
                return $this->url->getLink('admin/category', true, 'category not found.');
            }
            $aResults = $this->database->getListObject('SELECT * FROM categorys');
            $this->set(array('acategorys' => $aResults));
            $this->set(array('ocategory' => $ocategory));
        }
    }
?>
